# Step 1: Build the Java application
FROM maven:3.8-openjdk-8 as builder
WORKDIR /app
COPY backend/pom.xml .
COPY backend/src ./src
# Build and run unit tests
RUN mvn package -Dmaven.test.skip=false

# Step 2: Run the Java application
FROM openjdk:8-jre-slim
WORKDIR /app
# Copy the jar file from builder stage
COPY --from=builder /app/target/*.jar app.jar
# Expose backend port
EXPOSE 8080
# Start command
CMD ["java", "-jar", "app.jar"]